import { Component } from 'react'
import { BrowserRouter, Route } from 'react-router-dom'
import App from '../App'
import Login from '../views/Login'
import Admin from '../views/Admin'
import Home from '../components/layout/Home'
import GoodsList from '../views/GoodsList'
import GoodsInfo from '../views/GoodsInfo'

export default class Router extends Component {
  render () {
    // 一个 Route 组件就是一条路由规则
    // 这里展示了嵌套路由的写法
    // Home 组件需要 exact 精确匹配
    return (
      <BrowserRouter>
        <App>
          <Route path="/login" component={Login}/>
          <Route path="/admin" render={() => (
            <Admin>
              <Route path="/admin" component={Home} exact />
              <Route path="/admin/goods-list" component={GoodsList}/>
              <Route path="/admin/goods-info" component={GoodsInfo}/>
            </Admin>
          )}/>
        </App>
      </BrowserRouter>
    )
  }
}
